/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package byzantine;

/**
 *
 * @author rpathan
 */
public class Message {

    public final static String pathDelimiter = "_";
    private String path;
    private String value;
    private String calcValue;
    private boolean traitorMessage;

    public Message(String value, String path, String calcValue, boolean traitorMessage) {
        this.path = path;
        this.value = value;
        this.calcValue = calcValue;
        this.traitorMessage = traitorMessage;
    }

    public Message(Message m) {
        this.path = m.path;
        this.value = m.value;
        this.calcValue = m.calcValue;
    }

    public String getCalcValue() {
        return calcValue;
    }

    public void setCalcValue(String calcValue) {
        this.calcValue = calcValue;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public boolean pathContains(String ID) {
        String tokens[] = path.split(Message.pathDelimiter);
        for (String token : tokens) {
            if (token.equals(ID)) {
                return true;
            }
        }
        return false;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public boolean isTraitorMessage() {
        return traitorMessage;
    }

    public void setTraitorMessage(boolean traitorMessage) {
        this.traitorMessage = traitorMessage;
    }


    @Override
    public String toString() {
        if (traitorMessage) {
            return "(" + ByzantineModel.TRAITOR_VALUE + ", " + path + ", " + calcValue + ")";
        }
        return "(" + value + ", " + path + ", " + calcValue + ")";
    }

}
